<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深拷贝</title>
</head>

<body>
<script>
    const data = [{
        id: '1',
        name: '张三',
        age: 22,
        c: () => {
        }
    }, {
        id: '2',
        name: '李四',
        age: 23,
    }, {
        id: '3',
        name: '赵五',
        age: 22
    }]

    const copy = (data) => {
        let obj
        if (Array.isArray(data)) { // 如果是数组
            obj = []
            data.forEach(item => {
                obj.push(copy(item))
            })
        } else if (typeof data === 'object') { // 如果是对象
            obj = {}
            for (let index in data) {
                obj[index] = copy(data[index])
            }
        } else if ((typeof data).match(/^(string | number | boolean)$/)) {
            return data
        }
        return obj
    }

    console.log(copy(data))
</script>
</body>

</html>
